package br.ufpe.cin.dsoa.qos.service.registry.impl;

import java.util.List;

import org.apache.commons.math.stat.StatUtils;

//TODO: definir metodos para consultas temporais

public class ComputerStatistics implements Statistics {

	private RollingList rollingList;
	private int windowSize = 10;

	public ComputerStatistics() {
		this.rollingList = new RollingList(windowSize);
	}
	
	public ComputerStatistics(int windowSize) {
		this.rollingList = new RollingList(windowSize);
	}

	public int getWindowSize() {
		return windowSize;
	}

	public void setWindowSize(int windowSize) {
		this.windowSize = windowSize;
	}

	public void addValue(double value) {
		Data item = new Data(value, System.currentTimeMillis());
		rollingList.add(item);
	}

	@Override
	public double getGeometricMean() {
		return StatUtils.geometricMean(this.rollingList.getData());
	}

	@Override
	public double getMax() {
		return StatUtils.max(this.rollingList.getData());
	}

	@Override
	public double getMean() {
		return StatUtils.mean(this.rollingList.getData());
	}

	@Override
	public double getMin() {
		return StatUtils.min(this.rollingList.getData());
	}

	@Override
	public double getVariance() {
		return StatUtils.variance(this.rollingList.getData());
	}

	@Override
	public double getSumsq() {
		return StatUtils.sumSq(this.rollingList.getData());
	}

	@Override
	public double getPercentile(double p) {
		return StatUtils.percentile(this.rollingList.getData(), p);
	}

	@Override
	public List<Data> getData() {
		return rollingList.getList();
	}

	@Override
	public double getGeometricMean(int eventWindow) {
		return StatUtils.geometricMean(this.rollingList.getData(eventWindow));
	}

	@Override
	public double getMax(int eventWindow) {
		return StatUtils.max(this.rollingList.getData(eventWindow));
	}

	@Override
	public double getMean(int eventWindow) {
		return StatUtils.mean(this.rollingList.getData(eventWindow));
	}

	@Override
	public double getMin(int eventWindow) {
		return StatUtils.min(this.rollingList.getData(eventWindow));
	}

	@Override
	public double getVariance(int eventWindow) {
		return StatUtils.variance(this.rollingList.getData(eventWindow));
	}

	@Override
	public double getSumsq(int eventWindow) {
		return StatUtils.sumSq(this.rollingList.getData(eventWindow));
	}

	@Override
	public double getPercentile(int eventWindow, double p) {
		return StatUtils.percentile(this.rollingList.getData(eventWindow), p);
	}

	@Override
	public double getGeometricMean(long secondsAgo) {
		return StatUtils.geometricMean(this.rollingList.getData((long) secondsAgo));
	}

	@Override
	public double getMax(long secondsAgo) {
		return StatUtils.max(this.rollingList.getData((long) secondsAgo));
	}

	@Override
	public double getMean(long secondsAgo) {
		return StatUtils.mean(this.rollingList.getData((long) secondsAgo));
	}

	@Override
	public double getMin(long secondsAgo) {
		return StatUtils.min(this.rollingList.getData((long) secondsAgo));
	}

	@Override
	public double getVariance(long secondsAgo) {
		return StatUtils.variance(this.rollingList.getData((long) secondsAgo));
	}

	@Override
	public double getSumsq(long secondsAgo) {
		return StatUtils.sumSq(this.rollingList.getData((long) secondsAgo));
	}

	@Override
	public double getPercentile(long secondsAgo, double p) {
		return StatUtils.percentile(this.rollingList.getData((long) secondsAgo), p);
	}
}
